package com.dd.stack.redis.controller;

import com.dd.stack.common.util.Result;
import com.dd.stack.redis.service.inner.impl.ProductServiceImpl;
import com.dd.stack.redis.service.inner.impl.RedisCounterServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/1/30 15:54
 * @Description ProductController Redis简单缓存的使用
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/product")
@Api(tags = "Redis简单缓存的使用")
public class ProductController {

    private final ProductServiceImpl psi;
    private final RedisCounterServiceImpl rcsi;

    @GetMapping("/{id}")
    @ApiOperation("获取产品信息（首先从缓存获取）")
    public Result addProduct(@PathVariable("id") Long id) {
        return psi.getProduct(id);
    }

    @GetMapping("/visit-count/{id}")
    @ApiOperation("获取产品访问计数")
    public Result visitCount(@PathVariable("id") Long id) {
        return Result.success(rcsi.getProductCounter(id));
    }
}
